<?php
/**
* @software         [JiJinCMS]
* @author           [上海集锦信息科技有限公司]
* @website          [http://www.jijinweb.com]
* @email            [sunny@jijinweb.com]
**/
namespace app\admin\controller;
use think\facade\View;
use think\facade\Db;
use think\facade\Request;
class TemplateHistory extends \app\admin\controller\Admin{
    public function __construct(\think\App $app) {
        parent::__construct($app);
        $this->model=new \app\admin\model\TemplateHistoryModel();
        $this->TemplateModel=new \app\admin\model\TemplateModel();
        $this->TemplateRecycleModel=new \app\admin\model\TemplateRecycleModel();
    }
    //历吏记录
    public function index($template_id){
        $data=$this->model->where("template_id",$template_id)->order("addtime desc")->select();
        View::assign("data",$data);
        return View::fetch();
    }
    //比差异
    public function differ($template_id,$history_id){
        $history=$this->model->where("id",$history_id)->find();
        //当前模板
        $now_content=$this->TemplateModel->where(array("template_id"=>$template_id))->value("content");
        //当template没有信息的时候，从template_recycle表里找（用于通过回收站功能过来的模板）
        if(!$now_content){
            $now_content=$this->TemplateRecycleModel->where(array("template_id"=>$template_id))->value("content");
        }
        //代码转换
        $data["now_content"]=htmlspecialchars_decode($now_content);
        $data["history_content"]=htmlspecialchars_decode($history["content"]);        
        View::assign("data",$data);
        View::assign("pagetitle","差异对比");
        View::assign("history",$history);
        return View::fetch();
    }

}